# 复制整行： Ctrl + D
# 格式化：Ctrl + Alt + L
# 整体标注：Ctrl + /

# continue语句

# exercise 曾经的java题目
"""
100000元
当 >50000 每次交 5%
当 <=50000 每次交1000
可以经过多少次路口
while + break完成
"""

cash = 100000
sum = 0
while True:
    if cash > 50000:
        cash = cash * (1 - 0.05)
        sum += 1
    elif 1000 < cash <= 50000:  # 每次错这个1000
        cash -= 1000
        sum += 1
    else:
        break
print(sum)


# 函数

# exe

def cry():
    print("喵喵~")


cry()


def cal01():
    sum = 0
    for i in range(1, 1001):
        sum += i
    print(sum)


cal01()


def cal02(a):
    sum = 0
    for i in range(1, a + 1):
        sum += i
    print(sum)


cal02(100)


def get_sum(a1, a2):
    sum = a1 + a2
    print(sum)


get_sum(1, 2)

# 递归
# 暂时停滞

# 函数作为参数传递
print("=============")


def get_max(a1, a2):
    max = a1 if a1 > a2 else a2
    return max


def f1(fun, n1, n2):
    return fun(n1, n2)


def f2(fun, n1, n2):
    return n1 + n2, fun(n1, n2)


print(f1(get_max, 1, 2))
x, y = f2(get_max, 10, 20)
print(f"x: {x}, y: {y}")

# 匿名函数
print("++++++++++++++")


def f1(fun, n1, n2):
    return fun(n1, n2)


print(f1(lambda x, y: x + y, 1, 2))

"""

    数据容器
    --> 列表，元组，字符串，集合，字典

 """

print("--------------")


# 案例：鸡下蛋 java用过的
def f1():
    sum = 0
    id = 0
    for i in [3, 5, 1, 3.4, 2, 50, 2]:  # 列表表示
        sum += i
        id += 1
    print(sum)
    print(round((sum / id), 2))


f1()

# 列表正式开始
print("+++++列表+++++")
# 定义
list1 = ["a", "b", "c"]
list2 = list(range(1, 5))
print(list2)  # 定义可以被更换为其他的元素
print(list1[2])

# 遍历

print("for循环")
for i in list1:
    print(i)

print("while循环")
i = 0
while i < len(list1):
    print(list1[i])
    i += 1

# 列表元素类型任意
print("列表元素类型任意")
list1 = ["a", 2, True, 0.9, type(1)]
for i in list1:
    print(i)

# 添加和减少和修改元素
print("添加和减少和修改元素")
list2[0] = 3
list2[1] = 7

list2.append(100)  # 添加
list2.insert(1, "f")
print(list2)

del list2[1]  # 删除
print(list2)

list2.reverse()  # 反转
print(list2)

list2.sort()  # 整理
print(list2)

list2.clear()  # 清空
print(list2)

# 列表是可变序列
print("列表是可变序列,指向地址不变")
list3 = [1, 2, 3]
print(id(list3))
list3[0] = 2
print(id(list3))
list2 = list3
print(id(list2))

list2 = [1, 2, 3]
print(list2)
list(list2)  # 将元组[]转化为列表
print(list2)  # 定义可以被更换为其他的元素

# 列表生成式
print("列表生成式")
list1 = [ele * 2 for ele in range(10)]
print(list1)

list2 = [ele ** 2 for ele in range(10)]
print(list2)

# 循环输出五个成绩保存到列表并输出
print("循环输出五个成绩保存到列表并输出")

# list1 = list(range(0, 5))
# i = len(list1)
#
# while True:
#
#     a = int(input(f"请输入第{5 - i + 1}个成绩"))
#     list1[len(list1) - i] = a
#     i -= 1
#     if i == 0:
#         break
#
# print(list1)


# 元组
print("元组")
tuple1 = ("a", "b", "c")
for i in tuple1:
    print(i)

# exe

print("查询票价对应索引")
tuple2 = ('西游', '周星驰', 80, ['周星驰', '小甜甜'])
print(tuple2.index(80))

# 遍历所有演员
print("遍历所有演员")
for a in tuple2[3]:
    print(a)

# 删除小甜甜，添加牛魔王，朱八戒
print("删除小甜甜，添加牛魔王，朱八戒")
tuple2[3].remove("小甜甜")
tuple2[3].append("牛魔王")
tuple2[3].append("朱八戒")
print(tuple2)

# 字符串
print("字符串")

print(ord('a'))

# 取得字符串第三个值
str_a = "abcde"
print(str_a[2], type(str_a[2]))

#遍历
print("遍历")
str_b = "123456"
i = 0
while True:
    if i <= (len(str_b)-1):
        print(str_b[i])
        i += 1
    elif i >=(len(str_b)-1):
        break
print("for循环")
for i in range(0,len(str_b)):
    print(str_b[i])
    i += 1
    if i == len(str_b):
        break

#exe1
print("练习一")
str_names = "tom jack mary Mono smith hsp"
print(str_names.split())
print(len(str_names.split()))

print("for循环")
names_list = str_names.split()  # 将字符串转换为列表

for i in range(len(names_list)):
    if names_list[i] == "hsp":
        names_list[i] = "韩顺平"

# 将列表转换回字符串
str_names = " ".join(names_list)
print(str_names)


print(str_names.capitalize())

print(str_names.upper())
print(str_names.lower())
print(str_names.title())





# 切片




# 集合





# 字典



